<!-- 跑马灯信息-->

<template>
  <el-dialog
    :model-value="dialogFormVisible"
    :destroy-on-close="true"
    title="跑马灯信息"
    width="450px"
    @close="emits('closeDialog')"
  >
    <el-form
      ref="dialogFormRef"
      :model="dialogForm"
      :rules="rules"
      :label-width="formLabelWidth"
    >
      <el-form-item label="内容" prop="content">
        <el-input v-model="dialogForm.content" />
      </el-form-item>
      <el-form-item label="开始时间" prop="start_time">
        <el-date-picker
          v-model="dialogForm.start_time"
          type="datetime"
          format="YYYY/MM/DD HH:mm:ss"
        />
      </el-form-item>
      <el-form-item label="语言" prop="lang">
        <el-input v-model="dialogForm.lang" />
      </el-form-item>
      <el-form-item label="app标识" prop="app_mark">
        <el-input v-model="dialogForm.app_mark" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="emits('cancel')">取消</el-button>
        <el-button
          type="primary"
          @click="submit(dialogForm)"
          :loading="btnLoading"
        >
          提交
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref } from "vue";
const dialogFormRef = ref(null);

defineProps({
  dialogFormVisible: {
    type: Boolean,
    default: false,
  },
  dialogForm: {
    type: Object,
    default: {
      content: "",
      start_time: "",
      lang: "",
      app_mark: "",
    },
  },
  btnLoading: {
    type: Boolean,
    default: false,
  },
});
const emits = defineEmits(["closeDialog", "cancel", "submitForm"]);

const formLabelWidth = "120px";
// 校验
const rules = {
  content: [{ required: true, message: "请输入内容", trigger: "blur" }],
  start_time: [{ required: true, message: "请输入开始时间", trigger: "blur" }],
  lang: [{ required: true, message: "请输入语言", trigger: "blur" }],
  app_mark: [{ required: true, message: "请输入app标识", trigger: "blur" }],
};

// 提交
const submit = (dialogForm) => {
  dialogFormRef.value
    .validate()
    .then(async () => {
      try {
        dialogForm.start_time = dialogForm.start_time.valueOf() / 1000;
        emits("submitForm", dialogForm);
      } catch (error) {
        console.log(error);
      }
    })
    .catch((error) => {
      console.log(error);
    });
};
</script>
